/*
 * PrizeDialog.java
 * business
 *
 * Created by ChenTao on 2017/2/25.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.ui.assetabout.redpacket.RedPacketActivity;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.UIUtils;
import com.yidiandao.business.utils.UmengUtils;

/** 中奖对话框 */
public class PrizeDialog extends Dialog {

    private Activity mActivity;

    private ImageView mIvValue;

    private TextView mTvValue;

    private TextView mTvClose;

    private TextView mTvShow;

    public PrizeDialog(Context context) {
        super(context, R.style.ThemeNoTitleDialog);
        mActivity = (Activity) context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_prize);
        initViews();
        initListeners();
    }

    private void initViews() {
        mIvValue = (ImageView) findViewById(R.id.iv_value);
        mTvValue = (TextView) findViewById(R.id.tv_value);
        mTvClose = (TextView) findViewById(R.id.tv_close);
        mTvShow = (TextView) findViewById(R.id.tv_show);
    }

    private void initListeners() {
        mTvShow.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dismiss();
                        UmengUtils.onEvent(mActivity, R.string.umeng_check_raffle);
                        RedPacketActivity.actionStart(mActivity);
                    }
                });

        mTvClose.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dismiss();
                    }
                });
    }

    /**
     * @param info 中奖内容
     * @param path 中奖图片
     */
    public void setPrizeInfo(String info, String path) {
        mTvValue.setText(UIUtils.getString(R.string.prize_value, info));
        ImageLoader.loadImageFitXY(mActivity, mIvValue, path);
    }
}
